from motor.motor_asyncio import AsyncIOMotorClient
from loguru import logger
from app.core.config import CoreSettings, get_settings


settings: CoreSettings = get_settings()
MONGO_URI: str = f"mongodb://{settings.mongodb.host}:{settings.mongodb.port}/{settings.mongodb.database}"
mongodb_client = AsyncIOMotorClient(MONGO_URI, maxPoolSize=settings.mongodb.pool_size)

def mongo_provider():
    """
    获取mongodb连接
    :return:
    """
    db = mongodb_client.get_database()
    if db is None:
        logger.error("mongodb 连接失败")
    return db
